class CreateDatabase < ActiveRecord::Migration
  def self.up
    create_table "coeficientes", :force => true do |t|
      t.column "nombre", :string, :limit => 45, :default => "", :null => false
      t.column "desc",   :string, :limit => 45
    end
  
    create_table "comosupos", :force => true do |t|
      t.column "nombre", :string, :limit => 45, :default => "", :null => false
    end
  
    create_table "evasions", :force => true do |t|
      t.column "persona_id", :integer,  :limit => 10, :null => false
      t.column "fecha",      :date,               :null => false
      t.column "notas",      :text
    end
  
    create_table "gestions", :force => true do |t|
      t.column "alumno", :integer,  :limit => 10, :null => false
      t.column "fecha",  :datetime,               :null => false
      t.column "notas",  :text
    end
  
    add_index "gestions", ["alumno"], :name => "FK_gestions_personas"
  
    create_table "grados", :force => true do |t|
      t.column "nombre", :string, :limit => 45, :default => "", :null => false
    end
  
    create_table "horarios", :force => true do |t|
      t.column "nombre",        :string,  :limit => 45, :default => "", :null => false
      t.column "instructor_id", :integer, :limit => 10
    end
  
    add_index "horarios", ["instructor_id"], :name => "FK_horarios_instructors"
  
    create_table "instructors", :force => true do |t|
      t.column "nombre", :string, :limit => 45, :default => "", :null => false
    end
  
    create_table "matriculas", :force => true do |t|
      t.column "fecha",         :date,               :null => false
      t.column "instructor_id", :integer,  :limit => 10, :null => false
      t.column "persona_id",    :integer,  :limit => 10, :null => false
    end
  
    add_index "matriculas", ["instructor_id"], :name => "FK_matriculas_instructors"
    add_index "matriculas", ["persona_id"], :name => "FK_matriculas_personas"
  
    create_table "personas", :force => true do |t|
      t.column "dni",              :string,  :limit => 45
      t.column "nombres",          :string,  :limit => 45,  :default => "", :null => false
      t.column "apellidos",        :string,  :limit => 45
      t.column "dire",             :string,  :limit => 100
      t.column "tel",              :string,  :limit => 45
      t.column "cel",              :string,  :limit => 45
      t.column "mail",             :string,  :limit => 45
      t.column "grado_id",         :integer, :limit => 10,  :default => 1,  :null => false
      t.column "horario_id",       :integer, :limit => 10
      t.column "instructor_id",    :integer, :limit => 10
      t.column "coeficiente_id",   :integer, :limit => 10,                  :null => false
      t.column "genero",           :string,  :limit => 2,   :default => "", :null => false
      t.column "foto",             :string,  :limit => 200
    end
  
    add_index "personas", ["grado_id"], :name => "FK_personas_grados"
    add_index "personas", ["horario_id"], :name => "FK_personas_horarios"
    add_index "personas", ["instructor_id"], :name => "FK_personas_instructors"
    add_index "personas", ["coeficiente_id"], :name => "FK_personas_coeficientes"
  
    create_table "plans", :force => true do |t|
      t.column "nombre",    :string,   :limit => 45, :default => "",    :null => false
      t.column "ini",       :date,                                  :null => false
      t.column "fin",       :date,                                  :null => false
      t.column "alumno_id", :integer,  :limit => 10,                    :null => false
      t.column "vip",       :boolean,                :default => false, :null => false
      t.column "obs",       :text
    end
  
    add_index "plans", ["alumno_id"], :name => "FK_plans_personas"
  
    create_table "reunions", :force => true do |t|
      t.column "alumno", :integer,  :limit => 10, :null => false
      t.column "fecha",  :datetime,               :null => false
      t.column "notas",  :text
    end
  
    add_index "reunions", ["alumno"], :name => "FK_reunions_personas"
  
    create_table "revisacions", :force => true do |t|
      t.column "alumno", :integer,  :limit => 10, :null => false
      t.column "fecha",  :datetime,               :null => false
    end
  
    add_index "revisacions", ["alumno"], :name => "FK_revisacions_personas"
  
    create_table "visitas", :force => true do |t|
      t.column "persona_id",    :integer,  :limit => 10, :null => false
      t.column "fecha",         :datetime,               :null => false
      t.column "comosupo_id",   :integer,  :limit => 10
      t.column "obs",           :text
      t.column "instructor_id", :integer,  :limit => 10, :null => false
    end
  
    add_index "visitas", ["instructor_id"], :name => "FK_visitas_instructors"
    add_index "visitas", ["comosupo_id"], :name => "FK_visitas_comosupos"
    add_index "visitas", ["persona_id"], :name => "FK_visitas_personas"
    
    # Inicializa la tabla grados
    Grado.create :id=>Grado::ASPIRANTE, :nombre => 'Aspirante'
    Grado.create :id=>Grado::SADHAKA, :nombre => 'Sadhaka'
    Grado.create :id=>Grado::YOGIN, :nombre => 'Yogin'
    Grado.create :id=>Grado::CHELA, :nombre => 'Chela'
    Grado.create :id=>Grado::GRADUADO, :nombre => 'Graduado'
    Grado.create :id=>Grado::ASISTENTE, :nombre => 'Asistente'
    Grado.create :id=>Grado::DOCENTE, :nombre => 'Docente'
    Grado.create :id=>Grado::MAESTRO, :nombre => 'Maestro'
    
    # Inicializa la tabla coeficientes
    Coeficiente.create :id=>Coeficiente::FP, :nombre => 'FP'
    Coeficiente.create :id=>Coeficiente::PMENOS, :nombre => 'P-'
    Coeficiente.create :id=>Coeficiente::PERFIL, :nombre => 'P'
    Coeficiente.create :id=>Coeficiente::PMAS, :nombre => 'P+'
    Coeficiente.create :id=>Coeficiente::ALUMNO, :nombre => 'Alumno'
    Coeficiente.create :id=>Coeficiente::EXALUMNO, :nombre => 'Ex-Alumno'
    
    #Inicializa la tabla de comosupos
    
    Comosupo.create :nombre=>"Recomendado"
    Comosupo.create :nombre=>"Site"
    Comosupo.create :nombre=>"Libro"
    Comosupo.create :nombre=>"Flyer"
    Comosupo.create :nombre=>"Cartel"
    Comosupo.create :nombre=>"Otros"
  end
  
  def self.down
    drop_table "coeficientes"
    drop_table "comosupos"
    drop_table "evasions"
    drop_table "gestions"
    drop_table "grados"
    drop_table "horarios"
    drop_table "instructors"
    drop_table "matriculas"
    drop_table "personas"
    drop_table "plans"
    drop_table "reunions"
    drop_table "revisacions"
    drop_table "visitas"
  end
end
